/**
 * 商品档案操作控制类
 * MerchandiseAction.java
 * Copyright (C) 2013 Gank
 * Simple Currency Trade System
 * 
 */
package com.gank.ct.action;

import java.util.ArrayList;
import java.util.List;

import com.gank.ct.domain.Merchandise;
import com.gank.ct.service.IMerchandiseService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Copyright (C) 2013:Gank<br/>
 * Project:Curreny Trade<br/>
 * Module ID:<br/>
 * Comments:Simple Currency Trade System<br/>
 * JDK version used:JDK1.6<br/>
 * Package:com.gank.ct.action<br/>
 * Author:Michael Wu<br/>
 * Create Date:2013-11-3<br/>
 * Modified By:<br/>
 * Modified Date:<br/>
 * Why & What is modified:<br/>
 * Version:0.1<br/>
 */
@SuppressWarnings("serial")
public class MerchandiseAction extends ActionSupport {
	// 商品档案业务处理接口
	private IMerchandiseService merchandiseService;
	private Merchandise merchandise = new Merchandise();
	// 查询结果集
	private List<Merchandise> merchandises = new ArrayList<Merchandise>();
	// 操作结束后跳转的地址
	private String finish_Url;
	// 要删除的商品ID
	private String[] merchandiseId;

	/**
	 * 商品档案查询
	 * 
	 * @return
	 */

	public String findMerchandise() {
		merchandises = merchandiseService.findMerchandise(merchandise);
		return "findMerchandise";

	}

	/**
	 * 商品档案保存
	 * 
	 * @return
	 */
	public String saveMerchandise() {
		merchandiseService.saveMerchandise(merchandise);
		finish_Url = "merchandiseAction!findMerchandise.action";
		return "finish";
	}

	/**
	 * 商品档案删除
	 * 
	 * @return
	 */
	public String deleteMerchandise() {
		merchandiseService.deleteMerchandise(merchandiseId);
		finish_Url = "merchandiseAction!findMerchandise.action";
		return "finish";
	}

	/**
	 * 商品档案更新
	 * 
	 * @return
	 */
	public String updateMerchandise() {
		merchandiseService.updateMerchandise(merchandise);
		finish_Url = "merchandiseAction!findMerchandise.action";
		return "finish";
	}

	/**
	 * 商品档案更新前查询
	 * 
	 * @return
	 */
	public String preUpdateMerchandise() {
		merchandise = merchandiseService.findMerchandise(merchandise).get(0);
		return "updateMerchandise";
	}

	/**
	 * 商品档案查询
	 * 
	 * @param code
	 *            商品编码
	 * @return
	 */

	public int findMerchandiseByCode(String code) {
		merchandise = new Merchandise();
		merchandise.setCode(code);
		merchandises = merchandiseService.findMerchandise(merchandise);
		return merchandises.size();

	}

	/**
	 * @return the merchandiseService
	 */
	public IMerchandiseService getMerchandiseService() {
		return merchandiseService;
	}

	/**
	 * @param merchandiseService
	 *            the merchandiseService to set
	 */
	public void setMerchandiseService(IMerchandiseService merchandiseService) {
		this.merchandiseService = merchandiseService;
	}

	/**
	 * @return the merchandise
	 */
	public Merchandise getMerchandise() {
		return merchandise;
	}

	/**
	 * @param merchandise
	 *            the merchandise to set
	 */
	public void setMerchandise(Merchandise merchandise) {
		this.merchandise = merchandise;
	}

	/**
	 * @return the merchandises
	 */
	public List<Merchandise> getMerchandises() {
		return merchandises;
	}

	/**
	 * @param merchandises
	 *            the merchandises to set
	 */
	public void setMerchandises(List<Merchandise> merchandises) {
		this.merchandises = merchandises;
	}

	/**
	 * @return the finish_Url
	 */
	public String getFinish_Url() {
		return finish_Url;
	}

	/**
	 * @param finish_Url
	 *            the finish_Url to set
	 */
	public void setFinish_Url(String finish_Url) {
		this.finish_Url = finish_Url;
	}

	/**
	 * @return the merchandiseId
	 */
	public String[] getMerchandiseId() {
		return merchandiseId;
	}

	/**
	 * @param merchandiseId
	 *            the merchandiseId to set
	 */
	public void setMerchandiseId(String[] merchandiseId) {
		this.merchandiseId = merchandiseId;
	}

}
